# encoding: utf-8
import json
import requests
import sys

def init_journal_pub_cycle(file_name, token):
    journal_pub_cycle_create_url = "http://127.0.0.1:8000/literature/journal-publication-cycle"
    
    # token每次登录要改
    headers={"Content-Type": "application/json;charset=utf-8","Token": token}
    with open(file_name, 'r', encoding="utf-8") as f:
        data = json.load(f)
    for journal_pub_cycle_data in data:
        '''
        每个journal_pub_cycle_data格式如下:
        {
            "name": "",
            "zh_name": "",
        }
        '''
        ld = json.dumps(journal_pub_cycle_data, ensure_ascii=False).encode("utf-8")
        res = requests.post(journal_pub_cycle_create_url, data=ld, headers=headers)
        print(res.json())
        
if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("输入命令格式不对，请使用 python script_name.py <token>")
        sys.exit(1)
    
    token = sys.argv[1]
    
    init_journal_pub_cycle("../../files/journal_pub_cycle_data.json", token)
        